// Ninf-G-XX, ver. 0.1
// Copyright 2011 National Institute of Advanced Industrial Science and Technology
// 
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// 
//     http://www.apache.org/licenses/LICENSE-2.0
// 
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef __NC_GLOBAL_H__
#define __NC_GLOBAL_H__

#include <map>
#include <vector>
#include "Logger.hpp"
#include "FunctionInterface.hpp"
#include "DataInputStream.hpp"
#include "LogParser.hpp"
#include "SessionManager.hpp"

namespace ninf { 
namespace client {
  

#define UNIVERSE_STANDARD 0
#define UNIVERSE_VANILLA  1
#define UNIVERSE_GLOBUS   2

using namespace std;

struct ltstr
{
  bool operator()(const char* s1, const char* s2) const
  {
    return strcmp(s1, s2) < 0;
  }
};

class Global {
  bool readInfo(char * infoFilename);
  char * createRunDir();

public:
  // the instance
  static Global global;

  Global();

  Logger logger;
  map<const char *, FunctionInterface *, ltstr> interfaceMap;
  vector <char *> binDirs;
  int pid;

  // sessionManager 
  SessionManager     sessionManager;

  char * condorBinDir;
  char * currentDir;
  char * runDir;
  
  int executingJob;
  int maxExecuting;

  int universe;

  // read an interfaces in the directory and store them in the interfaceMap
  void readInterfaceDir(const char * dirname);

  // read an interface and store it in the interfaceMap
  void readInterface(const char * filename);

  // read an interface and store it in the interfaceMap
  void readInterface(DataInputStream & dis);

  // read configurationf file and initialize  global
  bool readConf(const char *filename);
  
  // parse argument options 
  int parseArg(int argc, char ** argv);

  // initialize
  void init();

};

#define MAX_LINE_LENGTH 1000

	}}

#endif
